# -*- coding:utf-8 -*-

import sys
from PySide6 import QtCore, QtGui, QtWidgets
from PySide6.QtCore import Qt
from PySide6.QtGui import QPalette, QColor
from PySide6.QtWidgets import QApplication, QWidget, QSlider, QLabel, QVBoxLayout, QFormLayout


class DemoSlider(QWidget):
    def __init__(self, parent=None):
        super(DemoSlider, self).__init__(parent)

        # 设置窗口标题
        self.setWindowTitle('实战PySide6: QSlider Demo!')
        # 设置窗口大小
        self.resize(400, 240)

        # 主布局为垂直布局
        vLayer = QVBoxLayout(self)

        # R,G,B颜色条
        self.frm_r = QWidget(self)
        self.frm_r.setMinimumHeight(32)
        self.frm_r.setAutoFillBackground(True)
        self.frm_g = QWidget(self)
        self.frm_g.setMinimumHeight(32)
        self.frm_g.setAutoFillBackground(True)
        self.frm_b = QWidget(self)
        self.frm_b.setMinimumHeight(32)
        self.frm_b.setAutoFillBackground(True)

        # form 布局
        fLayout = QFormLayout(self)
        fLayout.setHorizontalSpacing(20)
        fLayout.addRow(QLabel('Red', self), self.frm_r)
        fLayout.addRow(QLabel('Green', self), self.frm_g)
        fLayout.addRow(QLabel('Blue', self), self.frm_b)

        slider = QSlider(Qt.Horizontal, self)
        slider.setRange(0, 255)
        slider.setSingleStep(1)
        slider.setValue(128)
        slider.valueChanged.connect(self.sliderValueChanged)

        vLayer.addLayout(fLayout)
        vLayer.addSpacing(40)
        vLayer.addWidget(slider)
        vLayer.addStretch()

        self.setLayout(vLayer)

        # 设置初值
        self.sliderValueChanged(128)

    def sliderValueChanged(self, new_value):
        pass
        # pal = QPalette()
        # pal.setColor(QPalette.ColorRole, QColor(new_value, 0, 0))
        # self.frm_r.setPalette(pal)
        # pal.setColor(QPalette.ColorRole, QColor(0, new_value, 0))
        # self.frm_g.setPalette(pal)
        # pal.setColor(QPalette.ColorRole, QColor(0, 0, new_value))
        # self.frm_b.setPalette(pal)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = DemoSlider()
    window.show()
    sys.exit(app.exec())


